<template>
  <page-meta :page-style="'overflow:'+(show?'hidden':'visible')"></page-meta>
  <!-- <view
    :class="del ? '' : 'del'"
    style="background-color: rgb(246, 248, 251); padding-bottom: 0"
  >
  </view> -->
  <!-- <view class="tab" v-if="master">
    <view class="changjing" :class="isShow==0?'active':''" @click="isShow=0">场景</view>
    <view class="voice" :class="isShow==1?'active':''" @click="isShow=1">口播</view>
    <view class="line" :class="isShow==1?'line1':''"></view>
  </view> -->
  <view v-if="isShow==0" style="background-color: rgba(246, 248, 251, 1); overflow: hidden;">
    <view style="padding-bottom: 200rpx">
      <view class="items" v-for="(e, i) in arr" :key="i">
        <view class="title">
          <text v-if="master||publicity">{{e.name}}<text style="color: rgb(255,55,71);">*</text></text>
          <text v-else>场景{{ e }}<text v-if="i<=2" style="color: rgb(255,55,71);">*</text></text>
          <image
            @click="delMap(i)"
            v-if="e > 3&&!master"
            style="width: 48rpx; height: 48rpx"
            src="https://www.diandianyouke.site:801/fileDataBase/static/stag/static/img/home_schu.png"
            mode=""
          />
        </view>
        <view>
          <view class="videos">
            <view class="addVideo" @click="getSelectVideo(i + 1)">
              <image
                style="width: 80rpx; height: 75rpx"
                src="https://www.diandianyouke.site:801/fileDataBase/static/stag/static/img/icon_shipinsc.png"
                mode="scaleToFill"
              />
              <text style="font-size: 24rpx; color: rgba(142, 84, 244, 1)">添加视频</text>
            </view>
            <scroll-view
              scroll-x="true"
              style="white-space: nowrap; float: right; width: 520rpx; height: 200rpx;"
            >
              <view
                style="
                  padding-top: 18rpx;
                  display: inline-block;
                  position: relative;
                  width: 184rpx;
                  height: 178rpx;
                  box-sizing: border-box;
                "
                v-for="(item, index) in videoArr[i]"
                :key="index"
              >
                <video
                  :src="item"
                  style="
                    width: 160rpx;
                    height: 160rpx;
                    display: inline-block;
                    border-radius: 16rpx;
                  "
                ></video>
                <image
                  @click="delVideo(item, i)"
                  style="
                    width: 48rpx;
                    height: 48rpx;
                    position: absolute;
                    right: 0;
                    top: 0;
                  "
                  src="https://www.diandianyouke.site:801/fileDataBase/static/stag/static/img/xxxx.png"
                  mode=""
                />
              </view>
            </scroll-view>
          </view>
        </view>
      </view>
    </view>

    <view class="bottom">
      <!-- <twoButton
        v-if="!master"
        @leftClick="leftClick"
        @rightClick="gotoIP"
        left="添加场景"
        right="确认"
        :disable="disable"
      /> -->
      <!-- <btnModule @customClick="gotoIP" message="确认" /> -->
      <view class="bottom1">
        <button hover-class="hover" class="bottom-btn" :class="isReady?'tianjia-style':''" @click="gotoIP">确认</button>
      </view>
    </view>
  </view>
  <view v-if="isShow==1" style="background-color: rgb(246,248,251);overflow: hidden;padding-bottom: 200rpx;min-height:940rpx;">
    <view class="switch">
      <text >智能口播</text>
      <switch color="rgb(142,84,244)" @change="switch1Change" :checked="isSwitch" />
    </view>
    <view class="switch2" v-if="isSwitch">
      <text>宣传产品</text>
      <view @click="openPopup" class="product">{{templateId?templateId.product:'请选择模板'}}
        <image style="width: 48rpx;height: 48rpx;" src="https://www.diandianyouke.site:801/fileDataBase/static/stag/static/img/icon_yjtouz.png"/>
      </view>
    </view>
    <view class="items" v-else v-for="(e, i) in arr" :key="i">
      <!-- <view v-if="videoArr[i].length"> -->
        <view class="title">
          <text v-if="master||publicity">{{e.name}}<text v-if="i<=2" style="color: rgb(255,55,71);">*</text></text>
        </view>
        <view>
          <view class="videos">
            <view class="addVideo" @click="addVoice(i)">
              <image
                style="width: 96rpx; height: 96rpx"
                src="https://www.diandianyouke.site:801/fileDataBase/static/stag/static/img/icon_tjkbo.png"
                mode="scaleToFill"
              />
              <text style="font-size: 24rpx; color: rgba(142, 84, 244, 1)">添加口播</text>
            </view>
            <view
              style="overflow-x: scroll; white-space: nowrap; width: 520rpx;display: flex;align-items: center;"
            >
              <view
                style="
                  padding-top: 18rpx;
                  display: inline-block;
                  position: relative;
                  width: 160rpx;
                  height: 178rpx;
                  margin-right: 20rpx;
                "
                v-for="(item, index) in voiceList[i]"
                :key="index"
              >
                <view
                @click="editVoice(item, i,index)"
                  style="
                    width: 160rpx;
                    height: 160rpx;
                    border-radius: 16rpx;
                    padding: 16rpx;
                    display: flex;
                    justify-content: center;
                    align-items: center;
                    background-color: rgb(48,49,51);
                    color: #fff;
                    font-size: 20rpx;
                    box-sizing: border-box;
                    white-space: normal;
                  "
                > {{ item.content }}</view>
                <image
                  @click="delVoice(item, i,index)"
                  style="
                    width: 48rpx;
                    height: 48rpx;
                    position: absolute;
                    right: -16rpx;
                    top: 0;
                  "
                  src="https://www.diandianyouke.site:801/fileDataBase/static/stag/static/img/xxxx.png"
                  mode=""
                />
              </view>
            </view>
          </view>
        </view>
      <!-- </view> -->
    </view>
      <!-- <twoButton
      v-if="!isSwitch"
      @leftClick="openLibrary"
        @rightClick="getOk"
        left="口播库导入"
        right="确认"
        :disable="disable" /> -->
        <!-- <btnModule @customClick="goIP" message="确认"/> -->
        <view class="bottom1">
        <button class="bottom-btn" :class="!isReady?'tianjia-style':''" @click="goIP">确认</button>
      </view>
  </view>
  <uni-popup ref="popup" @change="popupChange" :safe-area="false">
    <view class="content">
      <view class="close">
        <image
          class="close-btn"
          @click="close"
          src="https://www.diandianyouke.site:801/fileDataBase/static/stag/static/img/list_button_Close.png"
          mode=""
        />
        文案库
        <text @click="addOk" class="addbtn" :class="!cusTitle ? 'disable' : ''"
          >新增</text
        >
      </view>
      <view style="overflow-y: scroll;width: 100%;height: 701rpx;padding-bottom: 325rpx;">
        <view class="item" :class="temId==item.id?'active-tem':''" @click="templateClick(item)" v-for="item in templates" :key="item.id">
        <view class="name">
              <text>商户名称</text>
              <text class="text">{{item.shopName}}</text>
            </view>
            <view class="name" style="color: rgba(142, 84, 244, 1);">
              <text>产品名称</text>
              <text class="text" style="color: rgba(142, 84, 244, 1);">{{item.product}}</text>
            </view>
            <view class="name">
              <text>产品价格</text>
              <text class="text">{{item.price}}</text>
            </view>
            <view class="name">
              <text>老板昵称</text>  
              <text class="text">{{item.character}}</text>
            </view>
            <view class="name">
              <text>从业年限</text>
              <text class="text">{{item.shopTime}}</text>
            </view>
            <view class="name" v-if="item.copy1">
              <text>宣传文案</text>
              <text class="text">{{item.copy1}}</text>
            </view>
            <view class="name" v-if="item.copy2">
              <text>宣传文案</text>
              <text class="text">{{item.copy2}}</text>
            </view>
      </view>
      <view class="flxed">
        <button @click="closePopup" class="tianjia tianjia-style">确认</button>
      </view>
      </view>
    </view>
  </uni-popup>
  <uni-popup ref="popupAdd" @change="popupChange">
      <view class="content">
        <view class="close">
        <image
          class="close-btn"
          @click="close"
          src="https://www.diandianyouke.site:801/fileDataBase/static/stag/static/img/list_button_Close.png"
          mode=""
        />
        {{arr[arrIndex].name}}
        <text @click="next" class="addbtn"
          >下一场景</text
        >
      </view>
      <view class="scroll">
        <text style="margin-right: 24rpx;">存入口播库</text>
        <switch style="transform:scale(0.7)" color="rgb(142,84,244)" @change="switch2Change" :checked="true" />
      </view>
      <view class="textarea"><fui-textarea height="120rpx" padding="0" :borderTop="false" :borderBottom="false" v-model="textarea" placeholder="请输入口播内容" placeholder-style="font-size:28rpx"></fui-textarea></view>
      <view class="zi">请输入10-15字 | <text :class="textarea.trim().length?'textarea-style':''">{{ textarea.trim().length }}字</text></view>
      <view class="flxed">
        <button @click="OoVoice" class="tianjia" :class="textarea.trim()?'tianjia-style':''">添加</button>
      </view>
      </view>
  </uni-popup>
  <uni-popup ref="add" @change="popupChange">
      <view class="content">
        <view class="close">
        <image
        v-if="isEdit"
          class="close-btn"
          @click="close('a')"
          src="https://www.diandianyouke.site:801/fileDataBase/static/stag/static/img/list_button_Close.png"
          mode=""
        />
        <image
        v-else
          class="close-btn"
          @click="back1"
          src="https://www.diandianyouke.site:801/fileDataBase/static/stag/static/img/tdian_icon_tjkbo_fhui.png"
          mode=""
        />
        {{isEdit?'修改口播':'添加新口播'}}
      </view>
      <scroll-view scroll-x class="scroll" v-if="!isEdit">
        <view class="scroll-item" v-for="item in arr" :key="item.id" @click="clickCate1(item)" :class="scrollText==item.id?'scroll-style':''">{{ item.name }}</view>
      </scroll-view>
      <view class="textarea" :style="isEdit?'margin-top: 30rpx;':''"><fui-textarea height="120rpx" padding="0" :borderTop="false" :borderBottom="false" v-model="textarea" placeholder="请输入口播内容" placeholder-style="font-size:28rpx"></fui-textarea></view>
      <view class="zi" :style="isEdit?'bottom: 705rpx;':''">请输入10-15字 | <text :class="textarea.trim().length?'textarea-style':''">{{ textarea.trim().length }}字</text></view>
      <view class="flxed">
        <button @click="addLibrary" class="tianjia" :class="textarea.trim()?'tianjia-style':''">{{isEdit?'修改':'添加'}}</button>
      </view>
      </view>
    </uni-popup>
  <uni-popup ref="library" @change="popupChange" :safe-area="false">
      <view class="content">
        <view class="close">
        <image
          class="close-btn"
          @click="close"
          src="https://www.diandianyouke.site:801/fileDataBase/static/stag/static/img/list_button_Close.png"
          mode=""
        />
        口播库
        <text @click="openAdd" class="addbtn"
          >新增</text
        >
      </view>
      <scroll-view scroll-x class="scroll">
        <view class="scroll-item" v-for="item in scrollCate" :key="item.id" @click="clickCate(item)" :class="scrollText==item.id?'scroll-style':''">{{ item.name }}</view>
      </scroll-view>
      <view class="kong" v-if="!voiceLibrary.length">
        <image style="width: 610rpx;height: 368rpx;" src="https://www.diandianyouke.site:801/fileDataBase/static/stag/static/img/state_empty.png"/>
        <text>暂无内容</text>
      </view>
      <view v-else class="list">
        <view class="library-item" :class="fun(item.id)?'active-item':''" @click="clickItem(item)" v-for="item in voiceLibrary" :key="item.id">
          {{ item.content }}
        </view>
        <view class="bottom-btn1">
        <view class="all" @click="checkAll">
          <aip-checkbox :check="isAll"></aip-checkbox>
          全选</view
        >
        <button class="verify" @click="verify">
          导入{{ isItem.length?isItem.length:'' }}
        </button>
      </view>
      </view>
      </view>
    </uni-popup>
  <uni-popup ref="addO" @change="popupChange">
    <view class="content">
      <view class="close">
        <image
          class="close-btn"
          @click="back"
          src="https://www.diandianyouke.site:801/fileDataBase/static/stag/static/img/tdian_icon_tjkbo_fhui.png"
          mode=""
        />
        文案库
      </view>
      <view class="from">
        <view class="name">
          <text>商户名称<text style="color: rgb(255,55,71);">*</text></text>
          <input v-model="shopName" class="input" type="text" placeholder="如xx店">
        </view>
        <view class="name">
          <text>产品名称<text style="color: rgb(255,55,71);">*</text></text>
          <input v-model="product" class="input" type="text" placeholder="如双人套餐">
        </view>
        <view class="name">
          <text>产品价格<text style="color: rgb(255,55,71);">*</text></text>
          <input v-model="price" class="input" type="text" placeholder="如29.9">
        </view>
        <view class="name">
          <text>老板昵称<text style="color: rgb(255,55,71);">*</text></text>
          <input v-model="character" class="input" type="text" placeholder="如王老板">
        </view>
        <view class="name">
          <text>从业年限<text style="color: rgb(255,55,71);">*</text></text>
          <input v-model="shopTime" class="input" type="text" placeholder="如20年">
        </view>
      </view>
      <view class="flxed">
        <button @click="addTem" class="tianjia tianjia-style">添加</button>
      </view>
    </view>
  </uni-popup>
</template>

<script setup>
import tips from "../../components/index/tips.vue";
import twoButton from "../../components/index/twoButton.vue";
import btnModule from "../../components/index/btnModule.vue";
import aipCheckbox from "../../components/index/aip-checkbox.vue"
import { debounce } from "../../utils/debounce";
import { httpRequest } from "../../utils/http";
import { useVideoStore } from "../../store/modules/video";
import { computed, ref } from "vue";
import { onLoad, onUnload } from "@dcloudio/uni-app";
const store = useVideoStore();
const content = ref(
  "成品视频由多个场景素材组成，每个场景建议不少于5条，以确保足够的成片数量"
);
const show = ref(false)
const del = ref(false);
const isShow = ref(0)
const videoArr1 = ref([]);
const videoArr2 = ref([]);
const videoArr3 = ref([]);
const videoArr4 = ref([]);
const videoArr5 = ref([]);
const videoArr6 = ref([]);
const videoArr7 = ref([]);
const videoArr = computed(() => [
  videoArr1.value,
  videoArr2.value,
  videoArr3.value,
  videoArr4.value,
  videoArr5.value,
  videoArr6.value,
  videoArr7.value,
]);
const voiceList1 = ref([]);
const voiceList2 = ref([]);
const voiceList3 = ref([]);
const voiceList4 = ref([]);
const voiceList5 = ref([]);
const voiceList6 = ref([]);
const voiceList7 = ref([]);
const voiceList = computed(() => [
  voiceList1.value,
  voiceList2.value,
  voiceList3.value,
  voiceList4.value,
  voiceList5.value,
  voiceList6.value,
  voiceList7.value,
]);

// if(uni.getStorageSync('voiceArr')){
//   voiceList.value = uni.getStorageSync('voiceArr')
//   voiceList1.value = uni.getStorageSync('voiceArr')[0]
//   voiceList2.value = uni.getStorageSync('voiceArr')[1]
//   voiceList3.value = uni.getStorageSync('voiceArr')[2]
//   voiceList4.value = uni.getStorageSync('voiceArr')[3]
//   voiceList5.value = uni.getStorageSync('voiceArr')[4]
//   voiceList6.value = uni.getStorageSync('voiceArr')[5]
//   voiceList7.value = uni.getStorageSync('voiceArr')[6]
// }
const textarea = ref('')
console.log(videoArr.value[0]);
const id = ref("");
const isChecked = ref(true);
const arr = ref([1, 2, 3]);
const isActive = ref("");
const disable = ref(true);
const isSave = ref(false);
const page = ref("");
const videoTime = ref(5)
const isCross = ref(0)
const master = ref('')
const templates = ref([])
const scrollCate = ref([])
const voiceLibrary = ref([])
const smart = ref('')
const oneClick = ref('')
const originality = ref('')
const publicity = ref('')
const isReady = ref(false)
onLoad(async(e) => {
  if(e.smart){
    smart.value = e.smart
  }
  if(e.oneClick){
    oneClick.value = e.oneClick
  }
  if(e.originality){
    originality.value = e.originality
  }
  if(e.publicity){
    publicity.value = e.publicity
    const res = await httpRequest('/api/shopCateVoiceCateByShopCate2Id','POST',{
        shopCate2Id:uni.getStorageSync('shop')[uni.getStorageSync('index')].shopCate2Obj.shopCate2Id
      })
      arr.value = res.data
  }
  if(e.master){
    master.value = e.master
    if(master.value){
      const res = await httpRequest('/api/shopCateVoiceCateByShopCate2Id','POST',{
        shopCate2Id:uni.getStorageSync('shop')[uni.getStorageSync('index')].shopCate2Obj.shopCate2Id
      })
      arr.value = res.data
      scrollCate.value = [{
    id:0,
    name:'全部'
  },...res.data]
      console.log(arr.value);
    }
  }
  if(e.same){
  if(uni.getStorageSync('same').time){
    videoTime.value =  Math.ceil(uni.getStorageSync('same').time/3)
  } 
  console.log(videoTime.value);
  }
  
  
  if (e.page) {
    page.value = e.page;
  }
  if (e.isChecked === "false") {
    isActive.value = false;
  } else {
    isActive.value = true;
  }
  getDraft();
});
onUnload(async () => {
  let a = videoArr.value.filter(e=>e.length)
  uni.setStorageSync('isCross', isCross.value)
  uni.setStorageSync('videoArr', a)
  if(master.value){
    // uni.setStorageSync('voiceArr',voiceList.value)
    // uni.setStorageSync('isItem',isItem.value)
    // uni.setStorageSync('templateId',templateId.value)
    // uni.setStorageSync('isSwitch',isSwitch.value)
  }
  //如果不是点击确认退出的页面就清除数据

  // if(isSave.value) return
  // await httpRequest('/api/delStaging','POST',{
  //   businessId: uni.getStorageSync("business").businessId,
  //   taskId:id
  // })
  // uni.removeStorageSync('videoArr')
  // uni.removeStorageSync('v1')
  // uni.removeStorageSync('v2')
  // uni.removeStorageSync('v3')
  // uni.removeStorageSync('v4')
  // uni.removeStorageSync('v5')
  // uni.removeStorageSync('v6')
  // uni.removeStorageSync('v7')
});
const delMap = (i) => {
  uni.showModal({
    title: "提示",
    content: "确认要删除吗?",
    success: (res) => {
      if (res.confirm) {
        console.log(i);
        videoArr.value[i].forEach((e) => {
          httpRequest("/api/delVideosOne2", "POST", {
            videoPath: e,
          });
          if (!videoArr.value.length) {
            httpRequest("/api/delTask", "POST", {
              taskId: uni.getStorageSync("taskId"),
            });
          }
        });
        if (i == 0) {
          videoArr1.value = [];
        } else if (i == 1) {
          videoArr2.value = [];
        } else if (i == 2) {
          videoArr3.value = [];
        } else if (i == 3) {
          videoArr4.value = [];
        } else if (i == 4) {
          videoArr5.value = [];
        } else if (i == 5) {
          videoArr6.value = [];
        } else {
          videoArr7.value = [];
        }
        arr.value.splice(i, 1);
      }
    },
  });
};

const popupChange = (e) => {
  show.value = e.show
  if(!e.show){
  isEdit.value = false
  }
}

const not = ref("");
const getDraft = async () => {
  const res = await httpRequest("/api/getVideosOne2", "POST", {
    businessId: uni.getStorageSync("business").businessId,
  });
  console.log(res);
  if (!res.data.length) return (not.value = 1);
  isCross.value = uni.getStorageSync('isCross')
  if (res.data[0]) {
    swich(res.data[0]);
  }
  if (res.data[1]) {
    swich(res.data[1]);
  }
  if (res.data[2]) {
    swich(res.data[2]);
  }
  if (res.data[3]) {
    swich(res.data[3]);
  }
  if (res.data[4]) {
    swich(res.data[4]);
  }
  if (res.data[5]) {
    swich(res.data[5]);
  }
  if (res.data[6]) {
    swich(res.data[6]);
  }
  console.log(videoArr.value);
   if(((master.value||publicity.value)&&(videoArr.value.filter(e=>e.length)).length==5)||(!master.value&&!publicity.value&&(videoArr.value.filter(e=>e.length)).length==3)){
      isReady.value = true
    }else{
      isReady.value = false
    }
};
const swich = (res) => {
  switch (res.index) {
    case 1:
      videoArr1.value = res.lists.map(e=>e.url);
      break;
    case 2:
      videoArr2.value = res.lists.map(e=>e.url);
      break;
    case 3:
      videoArr3.value = res.lists.map(e=>e.url);
      break;
    case 4:
      videoArr4.value = res.lists.map(e=>e.url);
      if(!master.value){
        arr.value = [1, 2, 3, 4];
      }
      break;
    case 5:
      videoArr5.value = res.lists.map(e=>e.url);
      if(!master.value){
        arr.value = [1, 2, 3, 4, 5];
      }
      break;
    case 6:
      videoArr6.value = res.lists.map(e=>e.url);
      if(!master.value){
        arr.value = [1, 2, 3, 4, 5, 6];
      }
      break;
    case 7:
      videoArr7.value = res.lists.map(e=>e.url);
      if(!master.value){
        arr.value = [1, 2, 3, 4, 5, 6, 7];
      }
      break;
    default:
      break;
  }
};
const delVideo = async (url, i) => {
  await httpRequest("/api/delVideosOne2", "POST", {
    videoPath: url,
  });
  if (i == 0) {
    videoArr1.value = videoArr1.value.filter((e) => e != url);
    uni.removeStorageSync("v1");
  } else if (i == 1) {
    videoArr2.value = videoArr2.value.filter((e) => e != url);
    uni.removeStorageSync("v2");
  } else if (i == 2) {
    videoArr3.value = videoArr3.value.filter((e) => e != url);
    uni.removeStorageSync("v3");
  } else if (i == 3) {
    videoArr4.value = videoArr4.value.filter((e) => e != url);
    uni.removeStorageSync("v4");
  } else if (i == 4) {
    videoArr5.value = videoArr5.value.filter((e) => e != url);
    uni.removeStorageSync("v5");
  } else if (i == 5) {
    videoArr6.value = videoArr6.value.filter((e) => e != url);
    uni.removeStorageSync("v6");
  } else {
    videoArr7.value = videoArr7.value.filter((e) => e != url);
    uni.removeStorageSync("v7");
  }
  console.log(videoArr.value);
  if (videoArr.value.every((e) => e.length == 0)) {
    await httpRequest("/api/delTask", "POST", {
      taskId: uni.getStorageSync("taskId"),
    });
    isCross.value = 0
    videoArr.value = [];
    uni.removeStorageSync("videoArr");
  }
  console.log((videoArr.value.filter(e=>e.length)).length);
  console.log((master.value&&(videoArr.value.filter(e=>e.length)).length==5)||(!master.value&&(videoArr.value.filter(e=>e.length)).length==3));
   if(((master.value||publicity.value)&&(videoArr.value.filter(e=>e.length)).length==5)||(!master.value&&!publicity.value&&(videoArr.value.filter(e=>e.length)).length==3)){
      isReady.value = true
    }else{
      isReady.value = false
    }
};
const leftClick = () => {
  if (arr.value.length == 7) return (disable.value = false);
  arr.value.push(arr.value[arr.value.length - 1] + 1);
  if (arr.value.length == 7) disable.value = false;
};
//上传视频
const getSelectVideo = (num) => {
  uni.vibrateShort()
  console.log(num);
  //选择视频
  uni.chooseVideo({
    maxDuration:60,
    // compressed:false,
    success: async (res) => {
      //查看视频信息
      // uni.getVideoInfo({
      //   src:res.tempFilePath,
      //   success: (res) => {
      //     console.log(res);
      //   ,
      // })}
      console.log(res);
      if(originality.value&&(res.height<res.width))return uni.showToast({title:`创意视频请统一上传竖屏的视频`,icon:'none'})
      if(publicity.value&&(res.height>res.width))return uni.showToast({title:`产品宣传请统一上传横屏的视频`,icon:'none'})
      if(num==1&&videoArr1.value+1>10)return uni.showToast({title:'上传视频不能超过十个'})
      if(num==2&&videoArr2.value+1>10)return uni.showToast({title:'上传视频不能超过十个'})
      if(num==3&&videoArr3.value+1>10)return uni.showToast({title:'上传视频不能超过十个'})
      if(num==4&&videoArr4.value+1>10)return uni.showToast({title:'上传视频不能超过十个'})
      if(num==5&&videoArr5.value+1>10)return uni.showToast({title:'上传视频不能超过十个'})
      if(num==6&&videoArr6.value+1>10)return uni.showToast({title:'上传视频不能超过十个'})
      if(num==7&&videoArr7.value+1>10)return uni.showToast({title:'上传视频不能超过十个'})
  
      console.log(videoTime.value);
      if (res.duration < videoTime.value)return uni.showToast({ title: `请上传至少${videoTime.value}秒的视频`, icon: "none" });
      console.log(master.value);
      if (master.value&&res.duration < 7)return uni.showToast({ title: `请上传至少7秒的视频`, icon: "none" });
      if (res.duration < 5)return uni.showToast({ title: `请上传至少5秒的视频`, icon: "none" });
      console.log(res.tempFilePath);
      
      if(!isCross.value){
        isCross.value = res.height>=res.width?1:2
      }
      console.log(isCross.value);
      if((isCross.value == 1&&res.height<res.width)||(isCross.value == 2&&res.height>=res.width)){
        uni.showToast({
          title:`请统一上传${isCross.value==1?'竖屏':'横屏'}的视频`,
          icon:'none'
        })
        return
      }
      uni.showLoading({
        title: "上传中",
        mask: true,
      });
      // uni.getVideoInfo({
      //   src:res.tempFilePath,
      //   success:(res)=>{
          console.log(res);
          uni.uploadFile({
        // url: 'https://www.diandianyouke.cn:8081/api/editVideosOne1',
        url: "https://www.diandianyouke.cn:8081/api/editVideosOne2",
        fileType: "video",
        filePath: res.tempFilePath,
        name: "video",
        header: {
          "Content-Type": "multipart/form-data",
          token: uni.getStorageSync("token"),
        },
        formData: { num: num,businessId:uni.getStorageSync('business').businessId,type:2, fblW:-1,fblH:-1},
        success: async ({ data, statusCode }) => {
          console.log(JSON.parse(data));
          if (JSON.parse(data).code == "0") {
            uni.hideLoading();
            uni.showToast({
              title: "上传成功",
              icon: "success",
              mask:false
            });
            if (num == 1) {
              videoArr1.value.push(JSON.parse(data).data);
              // videoArr.value[0].push(JSON.parse(data).data)
              uni.setStorageSync("v1", videoArr1.value);
            } else if (num == 2) {
              videoArr2.value.push(JSON.parse(data).data);
              uni.setStorageSync("v2", videoArr2.value);
              // videoArr.value[1].push(JSON.parse(data).data)
            } else if (num == 3) {
              videoArr3.value.push(JSON.parse(data).data);
              uni.setStorageSync("v3", videoArr3.value);
              // videoArr.value[2].push(JSON.parse(data).data)
            } else if (num == 4) {
              videoArr4.value.push(JSON.parse(data).data);
              uni.setStorageSync("v4", videoArr4.value);
              // videoArr.value[3].push(JSON.parse(data).data)
            } else if (num == 5) {
              videoArr5.value.push(JSON.parse(data).data);
              uni.setStorageSync("v5", videoArr5.value);
              // videoArr.value[4].push(JSON.parse(data).data)
            } else if (num == 6) {
              videoArr6.value.push(JSON.parse(data).data);
              uni.setStorageSync("v6", videoArr6.value);
              // videoArr.value[5].push(JSON.parse(data).data)
            } else {
              videoArr7.value.push(JSON.parse(data).data);
              uni.setStorageSync("v7", videoArr7.value);
              // videoArr.value[6].push(JSON.parse(data).data)
            }
            console.log(videoArr.value);
            if(((master.value||publicity.value)&&(videoArr.value.filter(e=>e.length)).length==5)||(!master.value&&!publicity.value&&(videoArr.value.filter(e=>e.length)).length==3)){
              isReady.value = true
            }else{
              isReady.value = false
            } 
          } else {
            uni.showToast({title:'上传失败',icon:'error'})
          }
          //   if(!videoArr.value.every(e=>e.length==0)&&not.value==1){

          // } else {
          //   uni.hideLoading();
          //   uni.showToast({
          //     title: "上传失败",
          //     icon: "none",
          //     mask: true,
          //   });
          // }

          // },
        },
        fail: (error) => {
          console.log(error);
          uni.showToast({title:'上传失败,请重试',icon:'error'})
        },
      });
      //   },
      //   fail:(err)=>{
      //     console.log(err);
      //   }
      // })
      const res1 = await httpRequest("/api/findTaskStart", "POST", {
              businessId: uni.getStorageSync("business").businessId,
            });
            console.log(res1);
            if (!res1.data) {
              let type = 'smart';
              if(smart.value){
                type = 'smart'
              }
              if(oneClick.value){
                type = 'oneClick'
              }
              if(uni.getStorageSync("same") && page.value == "same"){
                type='same'
              }
              if(master.value){
                type='master'+master.value
              }
              if(originality.value){
                type='ori'
              }
              if(publicity.value){
                type='pub1'
              }
              const res2 = await uni.request({
                url: "https://www.diandianyouke.cn:8081/api/addTask",
                method: "POST",
                header: {
                  "Content-Type": "application/json",
                },
                data: {
                  businessId: uni.getStorageSync("business").businessId,
                  shopId: uni.getStorageSync("shop")[uni.getStorageSync("index")].shopId,
                  type: type,
                },
              });
              uni.setStorageSync("taskId", res2.data.data.id);
              httpRequest('/api/generateTitle','POST',{
                shopId:uni.getStorageSync("shop")[uni.getStorageSync("index")].shopId,
                taskId:res2.data.data.id,
                // product:uni.getStorageSync('templateId')?uni.getStorageSync('templateId').product:''
              })
              uni.hideLoading()
              if(type=='same'){
                httpRequest('/api/downloadPopVideoVoice','POST',{
                  id:uni.getStorageSync('same').popVideoId,
                  businessId:uni.getStorageSync('business').businessId
                },20000)
              }
              if(master.value){
                uni.setStorageSync("prevPage", 'master');
              }
            }
    },
    fail: (error) => {
      console.error("读取文件失败", error);
    },
  });
};
//   fail: (err) => {
//     console.log(err);
//   },
// });
//   uni.chooseVideo({
//     maxDuration: "60",
//     success: (res) => {
//       if (count.value > res.duration)
//         return uni.showToast({ title: "剪辑时长大于视频总时长", icon: "none" });
//       // isProgress.value = true
//       console.log(res);
//       uni.showLoading({
//         title: "上传中",
//         mask: true,
//       });
//       const uploadTask = uni.uploadFile({
//         // url: 'https://www.diandianyouke.cn:8081/api/editVideosOne2',
//         //   url: "https://www.diandianyouke.cn:8081/api/editVideosOne2",
//         url: "https://www.diandianyouke.cn:8081/api/editVideosOne2",
//         fileType: "video",
//         filePath: res.tempFilePath,
//         name: "video",
//         header: {
//           "Content-Type": "multipart/form-data",
//           token: uni.getStorageSync("token"),
//         },
//         success: async ({ data, statusCode }) => {
//           console.log(JSON.parse(data));
//           if (JSON.parse(data).code == "0") {
//             uni.hideLoading();
//             uni.showToast({
//               title: "上传成功",
//               icon: "success",
//               mask: true,
//             });
//             longPath.value = res.tempFilePath;
//             uni.setStorageSync("active", true);

//             // checked.value = false
//             const res1 = await httpRequest("/api/clipVideosOne2", "POST", {
//               childTime: count.value,
//               videoTime: res.duration,
//               video: JSON.parse(data).data,
//             });

//             uni.setStorageSync("maxNum", res1.data);
//             uni.setStorageSync("videoTime", count.value);
//           } else {
//             uni.hideLoading();
//             uni.showToast({
//               title: "上传失败",
//               icon: "none",
//               mask: true,
//             });
//           }

//           // },
//         },
//         fail: (error) => {
//           console.log(error);
//         },
//       });
//       // uploadTask.onProgressUpdate(res=>{
//       // 	progress.value = res.progress
//       // 	if(res.progress == 100)return isProgress.value = false
//       // })
//     },
//     fail: (err) => {
//       console.log(err);
//     },
//   });
// 	})
// }
const gotoIP = async () => {
 if(!isReady.value) return
  if (!videoArr1.value.length||!videoArr2.value.length||!videoArr3.value.length) {
    isShow.value = 0
    uni.showToast({
      title: "请上传必传场景",
      icon: "none",
    });
    return 
  }
    
  //   if(master.value){
  //     let name = 0

  //   videoArr.value.forEach((e,i)=>{
  //   if(e.length){
  //   console.log(e.length);
  //   console.log(voiceList.value[i].length);
  //     if(!voiceList.value[i].length){
  //       name = arr.value[i].name
  //     }
  //   }
  // })
  //     if (name) {
  //     isShow.value = 1
  //       uni.showToast({
  //         title: `请上传${name}场景的口播素材`,
  //         icon: 'none'
  //       })
  //       return 
  //     }
  //     }
      
  uni.showLoading({
    title: "上传中",
    mask: true,
  });
  uni.hideLoading();
  uni.navigateBack({ delta: 1 });
  let a = videoArr.value.filter(e=>e.length)
  uni.setStorageSync("videoArr", a);
};

const isSwitch = ref(true)
if(uni.getStorageSync('isSwitch')===false){
  isSwitch.value = false
}
console.log('开关',isSwitch.value);
const switch1Change = (e) => {
  isSwitch.value = e.detail.value
}

const popup = ref(null)
const openPopup = () => {
  popup.value.open('bottom')
}

const add = ref(null)
const openAdd = () => {
  library.value.close()
  add.value.open('bottom')
  scrollText.value?scrollText.value:scrollText.value=1
}

const close = (e) => {
  if(e=='a'){
    add.value.close()
  }
  popup.value.close()
  popupAdd.value.close()
  library.value.close()
}

const back = () => {
  addO.value.close()
  popup.value.open('bottom')
}
const back1 = () => {
  add.value.close()
  library.value.open('bottom')

}

const library = ref(null)
const openLibrary = () => {
  library.value.open('bottom')
}

const goIP = () => {
  if (
    !videoArr1.value.length||
      !videoArr2.value.length||
      !videoArr3.value.length
  ) {
    isShow.value = 0
    uni.showToast({
      title: "请上传必传场景",
      icon: "none",
    });
    return 
  }
    
  uni.navigateBack({ delta: 1 })
}

const popupAdd = ref(null)
const arrIndex = ref(0)
const addVoice = (e) => {
  arrIndex.value = e
  console.log(popupAdd.value);
  popupAdd.value.open('bottom')
}

const isAll = ref(false)
const checkAll = () => {
  isAll.value = !isAll.value
  if(isAll.value){
    isItem.value = voiceLibrary.value
  }else{
    isItem.value = []
  }
}

const isItem = ref(uni.getStorageSync('isItem')||[])
const clickItem = (item) => {
  if(fun(item.id)){
    isItem.value = isItem.value.filter(e=>e.id!=item.id)
    isAll.value = false
  }else{
    isItem.value.push(item)
    if(isItem.value.length == voiceLibrary.value.length){
      isAll.value = true
    }
  }
}

const fun = (id) => {
  console.log(isItem.value);
  let a = false
  isItem.value.forEach(e=>{
    if(e.id==id){
      a = true
    }
  })
  return a
}

const isEdit = ref(false)
const item = ref('')
const i1 = ref('')
const index1 = ref('')
const editVoice = (e,i,index) => {
  isEdit.value = true
  item.value = e
  i1.value = i
  index1.value = index
  textarea.value = e.content
  add.value.open('bottom')
}

//导入
const verify = () => {
  let li = []
  isItem.value.forEach(e=>{
    if(!voiceList1.value.some(item=>item.id==e.id)&&!voiceList2.value.some(item=>item.id==e.id)&&!voiceList3.value.some(item=>item.id==e.id)&&!voiceList4.value.some(item=>item.id==e.id)&&!voiceList5.value.some(item=>item.id==e.id)){
      li.push(e)
    }
  })
  // isItem.value = li
  let v1 = li.filter(e=>e.voiceCateId==1)
  let v2 = li.filter(e=>e.voiceCateId==2)
  let v3 = li.filter(e=>e.voiceCateId==3)
  let v4 = li.filter(e=>e.voiceCateId==4)
  let v5 = li.filter(e=>e.voiceCateId==5)
  let v6 = li.filter(e=>e.voiceCateId==6)
  let v7 = li.filter(e=>e.voiceCateId==7)
  if(voiceList1.value.concat(v1).length>10
  ||voiceList2.value.concat(v2).length>10
  ||voiceList3.value.concat(v3).length>10
  ||voiceList4.value.concat(v4).length>10
  ||voiceList5.value.concat(v5).length>10
  ||voiceList6.value.concat(v6).length>10
  ||voiceList7.value.concat(v7).length>10
  )return uni.showToast({
    title: '场景口播最多上传10个',
    icon: 'none'
  })
  console.log(v1.length)
  console.log(v2.length)
  console.log(v3.length)
  console.log(v4.length)
  console.log(v5.length)
  console.log(v6.length)
  console.log(v7.length)
  voiceList1.value = voiceList1.value.concat(v1)
  voiceList2.value = voiceList2.value.concat(v2)
  voiceList3.value = voiceList3.value.concat(v3)
  if(videoArr4.value.length) {voiceList4.value = voiceList4.value.concat(v4)}else if(v4.length){uni.showToast({title:'请先上传该场景视频',icon:'none'})}
  if(videoArr5.value.length) {voiceList5.value = voiceList5.value.concat(v5)}else if(v5.length){uni.showToast({title:'请先上传该场景视频',icon:'none'})}
  if(videoArr6.value.length) {voiceList6.value = voiceList6.value.concat(v6)}else if(v6.length){uni.showToast({title:'请先上传该场景视频',icon:'none'})}
  if(videoArr7.value.length) {voiceList7.value = voiceList7.value.concat(v7)}else if(v7.length){uni.showToast({title:'请先上传该场景视频',icon:'none'})}
library.value.close()
// isItem.value = []
// isAll.value = false
}

const delVoice = (e,i,index) => {
  
  uni.showModal({
    title: '提示',
    content: '确定要删除吗?',
    success: ({ confirm, cancel }) => {
      if(confirm){
        if(e.m4aPath2){
          httpRequest('/api/delStagFile','POST',{
           videoPath:e.m4aPath
          })
        }
  if(i == 0){
    voiceList1.value.splice(index,1)
  }else if(i == 1){
    voiceList2.value.splice(index,1)
  }else if(i == 2){
    voiceList3.value.splice(index,1)
  }else if(i == 3){
    voiceList4.value.splice(index,1)
  }else if(i == 4){
    voiceList5.value.splice(index,1)
  }else if(i == 5){
    voiceList6.value.splice(index,1)
  }else if(i == 6){
    voiceList7.value.splice(index,1)
  }
      }
    }
  })
}

const next = () => {
  console.log(arr.value);
  console.log(arr.value.length,arrIndex.value);
  if(arr.value.length<=(arrIndex.value+1)){
    arrIndex.value = 0
  } else {
    textarea.value = ''
    arrIndex.value++
  }
}

const isSav = ref(true)
const switch2Change = (e) => {
  isSav.value = e.detail.value
}

const OoVoice = async() => {
  if(textarea.value.trim().length<10||textarea.value.trim().length>15)return uni.showToast({
    title: '请输入10-15个字',
    icon: 'none'
  })
  uni.showLoading({
    title: '加载中',
    mask: true
  })
  if(arrIndex.value == 3){
    if(!videoArr4.value.length) return uni.showToast({title:'请先上传该场景视频',icon:'none'})
  }else if(arrIndex.value == 4){
    if(!videoArr5.value.length) return uni.showToast({title:'请先上传该场景视频',icon:'none'})
  }else if(arrIndex.value == 5){
    if(!videoArr6.value.length) return uni.showToast({title:'请先上传该场景视频',icon:'none'})
  }else if(arrIndex.value == 6){
    if(!videoArr7.value.length) return uni.showToast({title:'请先上传该场景视频',icon:'none'})
  }
  const res = await uni.request({
    url: 'https://www.diandianyouke.cn:8081/api/addShopVoiceCopy',
    data: {
    content:textarea.value.trim(),
    type:1,
    voiceCateId:arr.value[arrIndex.value].id,
    shopId:uni.getStorageSync('shop')[uni.getStorageSync('index')].shopId,
    m4aPath2:isSav.value?'':1
  },
    header: {
      Accept: 'application/json',
      'Content-Type': 'application/json',
    },
    method: 'POST',
  })
  uni.hideLoading()
  console.log(res.data);
  if(arrIndex.value == 0){
    voiceList1.value = [...voiceList1.value,res.data.data]
  }else if(arrIndex.value == 1){
    voiceList2.value = [...voiceList2.value,res.data.data]
  }else if(arrIndex.value == 2){
    voiceList3.value = [...voiceList3.value,res.data.data]
  }else if(arrIndex.value == 3){
    if(!videoArr4.value.length) return uni.showToast({title:'请先上传该场景视频',icon:'none'})
    voiceList4.value = [...voiceList4.value,res.data.data]
  }else if(arrIndex.value == 4){
    if(!videoArr5.value.length) return uni.showToast({title:'请先上传该场景视频',icon:'none'})
    voiceList5.value = [...voiceList5.value,res.data.data]
  }else if(arrIndex.value == 5){
    if(!videoArr6.value.length) return uni.showToast({title:'请先上传该场景视频',icon:'none'})
    voiceList6.value = [...voiceList6.value,res.data.data]
  }else if(arrIndex.value == 6){
    if(!videoArr7.value.length) return uni.showToast({title:'请先上传该场景视频',icon:'none'})
    voiceList7.value = [...voiceList7.value,res.data.data]
  }
  textarea.value = ''
}

const scrollText = ref(0)
const clickCate = async(e) => {
  scrollText.value = e.id
  const res = await httpRequest('/api/getShopVoiceCopyByShopIdAndCateId','POST',{
    shopId:uni.getStorageSync('shop')[uni.getStorageSync('index')].shopId,
    voiceCateId:e.id,
    type:1
  })
  voiceLibrary.value = res.data
  // let o = voiceLibrary.value.every(item=>fun(item.id))
  // if(o){
  //   isAll = true
  // }else{
  //   isAll = false
  // }
}

const clickCate1 = (item) => {
  scrollText.value = item.id
}

//添加
const addLibrary = async() => {
  if(textarea.value.trim().length<10||textarea.value.trim().length>15)return uni.showToast({
    title: '请输入10-15个字',
    icon: 'none'
  })
  uni.showLoading({
    title: '加载中',
    mask: true
  })
  console.log(item.value);
if(isEdit.value){
  //修改
  if(item.value.m4aPath2){
    httpRequest('/api/delStagFile','POST',{
    videoPath:item.value.m4aPath
  })
  }else{
    httpRequest('/api/delShopVoiceCopy','POST',{
      shopVoiceCopyId:item.value.id
    })
  }
  
  const res = await uni.request({
    url: 'https://www.diandianyouke.cn:8081/api/addShopVoiceCopy',
    data: {
    content:textarea.value.trim(),
    type:1,
    voiceCateId:item.value.voiceCateId,
    shopId:uni.getStorageSync('shop')[uni.getStorageSync('index')].shopId,
    m4aPath2:item.value.m4aPath2?1:''
  },
    header: {
      Accept: 'application/json',
      'Content-Type': 'application/json',
    },
    method: 'POST',
  })
  uni.hideLoading()
  console.log(res);
  if(i1.value == 0){
    voiceList1.value.splice(index1.value,1)
    voiceList1.value.splice(index1.value,0,res.data.data)
  }else if(i1.value == 1){
    voiceList2.value.splice(index1.value,1)
    voiceList2.value.splice(index1.value,0,res.data.data)
  }else if(i1.value == 2){
    voiceList3.value.splice(index1.value,1)
    voiceList3.value.splice(index1.value,0,res.data.data)
  }else if(i1.value == 3){
    voiceList4.value.splice(index1.value,1)
    voiceList4.value.splice(index1.value,0,res.data.data)
  }else if(i1.value == 4){
    voiceList5.value.splice(index1.value,1)
    voiceList5.value.splice(index1.value,0,res.data.data)
  }else if(i1.value == 5){
    voiceList6.value.splice(index1.value,1)
    voiceList6.value.splice(index1.value,0,res.data.data)
  }else if(i1.value == 6){
    voiceList7.value.splice(index1.value,1)
    voiceList7.value.splice(index1.value,0,res.data.data)
  }
  if(res.data.data){
    uni.showToast({
      title:'修改成功',
      icon:'none'
    })
    textarea.value = ''
    add.value.close()
  }else{
    uni.showToast({
      title:'修改失败',
      icon:'error'
    })
  }
}else{
  const res = await uni.request({
    url: 'https://www.diandianyouke.cn:8081/api/addShopVoiceCopy',
    data: {
    content:textarea.value.trim(),
    type:1,
    voiceCateId:scrollText.value?scrollText.value:1,
    shopId:uni.getStorageSync('shop')[uni.getStorageSync('index')].shopId
  },
    header: {
      Accept: 'application/json',
      'Content-Type': 'application/json',
    },
    method: 'POST',
  })
  uni.hideLoading()
  console.log(res);
  if(res.data.data){
    uni.showToast({
      title:'添加成功',
      icon:'none'
    })
    textarea.value = ''
  }else{
    uni.showToast({
      title:'添加失败',
      icon:'error'
    })
  }
}

  
}

const templateId = ref(uni.getStorageSync('templateId')||'')
if(!templateId.value) {
  templateId.value = templates.value.forEach(e=>{
    return e.m===true
  })
}
const temId = ref(templateId.value?templateId.value.id:'')
const templateClick = (e) => {
  templateId.value = e
  temId.value = e.id
}

const shopName = ref(uni.getStorageSync('shop')[uni.getStorageSync('index')].shopName||'')
const shopTime = ref('')
const product = ref('')
const price = ref('')
const character = ref('')
//添加template
const addTem = async() => {
  if(!shopName.value.trim().length)return uni.showToast({title: '请输入店名',icon: 'none'})
  if(!shopTime.value.trim().length)return uni.showToast({title: '请输入从业年限',icon: 'none'})
  if(!product.value.trim().length)return uni.showToast({title: '请输入产品名称',icon: 'none'})
  if(!price.value.trim().length)return uni.showToast({title: '请输入产品价格',icon: 'none'})
  if(!character.value.trim().length)return uni.showToast({title: '请输入老板昵称',icon: 'none'})
  //新增文案
uni.showLoading({
  title: '加载中',
  mask: true
})
  const res = await uni.request({
      url: 'https://www.diandianyouke.cn:8081/api/addTemplate',
      data: {
        shopName:shopName.value.trim(),
        shopTime:shopTime.value.trim(),
        product:product.value.trim(),
        price:price.value.trim(),
        character:character.value.trim(),
        shopId:uni.getStorageSync('shop')[uni.getStorageSync('index')].shopId
      },
      timeout:50000,
      header: {
        Accept: 'application/json',
        'Content-Type': 'application/json',
      },
      method: 'POST',
    })
    //新增完成后设置为当前选择
    templateId.value = res.data.data
    temId.value = res.data.data.id
    uni.hideLoading()
    uni.showToast({
      title:'添加成功',
      icon:'none'
    })
    getTemplate()
    addO.value.close()
    // popup.value.open('bottom')
    shopTime.value = ''
    product.value = ''
    price.value = ''
    character.value = ''
}

const closePopup = () => {
  popup.value.close()
}

const addO = ref(null)
const addOk = () => {
  closePopup()
  addO.value.open('bottom')
}

const getLibrary = async() => {
  const res = await httpRequest('/api/getShopVoiceCopyByShopIdAndCateId','POST',{
    shopId:uni.getStorageSync('shop')[uni.getStorageSync('index')].shopId,
    voiceCateId:0,
    type:1
  })
  console.log(res);
  voiceLibrary.value = res.data
}
getLibrary()
//查询模板
const getTemplate = async() => {
  const res = await httpRequest('/api/getTemplate','POST',{
    shopId:uni.getStorageSync('shop')[uni.getStorageSync('index')].shopId
  })
  console.log(res);
  let x = res.data
  let n = 0
  x.forEach((e,i)=>{
    if(e.moRen==2){
      e.m=true
      if(!templateId.value){
        templateId.value = e
      }
      if(!temId.value){
        temId.value = e.id
      }
      n++
    }else{
      e.m = false
    }
    if(e.moRen == 1){
      x.splice(i,1)
      x.unshift(e)
      if(!temId.value){
        temId.value = e.id
      }
    }
  })
  if(!n){
    x.forEach(e=>{
    if(e.moRen==1){
      e.m=true
      if(!templateId.value){
        templateId.value = e
      }
      if(temId.value){
        temId.value = e.id
      }
    }
  })
  }
  templates.value = x
}
getTemplate();

const getOk = () => {
  let name = 0
    videoArr.value.forEach((e,i)=>{
    if(e.length){
    console.log(e.length);
    console.log(voiceList.value[i].length);
      if(!voiceList.value[i].length){
        name = arr.value[i].name
      }
    }
  })
  if(name){
    return uni.showToast({
          title: `请上传${name}场景的口播素材`,
          icon: 'none'
        })
  }
  
  if (
    !videoArr1.value.length||
      !videoArr2.value.length||
      !videoArr3.value.length
  ) {
    isShow.value = 0
    uni.showToast({
      title: "请上传必传场景",
      icon: "none",
    });
    return 
  }
    
  uni.showLoading({
    title: "上传中",
    mask: true,
  });
  uni.hideLoading();
  uni.navigateBack({ delta: 1 });
  let a = videoArr.value.filter(e=>e.length)
  uni.setStorageSync("videoArr", a);
  // uni.setStorageSync("voiceArr", voiceList.value);
  // uni.setStorageSync("isItem", isItem.value);
}

</script>

<style lang="scss" scoped>
.switch{
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 690rpx;
    height: 116rpx;
    margin: 30rpx;
    padding: 30rpx;
    box-sizing: border-box;
    font-size: 30rpx;
    font-weight: 500;
    color: #45464a;
    background-color: #fff;
    border-radius: 16rpx;
}
.switch2{
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 690rpx;
  height: 108rpx;
  margin: 0 30rpx;
  padding: 30rpx;
  box-sizing: border-box;
  font-size: 28rpx;
  color: rgb(69,70,74);
  background-color: #fff;
    border-radius: 16rpx;
  .product{
    display: flex;
    align-items: center;
    font-size: 28rpx;
    color: rgba(142, 84, 244, 1);
  }
}

.tab{
  width: 100%;
  height: 102rpx;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  .line{
    position: absolute;
    bottom: 0;
    width: 32rpx;
    height: 6rpx;
    background-color: #8e54f4;
    border-radius: 118rpx;
    transition: all .5s;
    transform: translate(-56rpx);
        }
        .line1{
          transform: translate(56rpx);
        }
  .changjing{
    width: 64rpx;
    height: 102rpx;
    text-align: center;
    line-height: 102rpx;
    margin-right: 48rpx;
    font-size: 32rpx;
    font-weight: 500;
    color: rgb(144,147,153);
  }
  .voice{
    width: 64rpx;
    height: 102rpx;
    text-align: center;
    line-height: 102rpx;
    font-size: 32rpx;
    font-weight: 500;
    color: rgb(144,147,153);
  }
  .active{
    // border-bottom: 1px solid rgba(142, 84, 244, 1);
    color: rgba(142, 84, 244, 1);
  }
}
.items {
  padding: 36rpx 30rpx;
  margin-top: 24rpx;
  background-color: #fff;
  .title {
    display: flex;
    justify-content: space-between;
    align-items: center;
    line-height: 96rpx;
    font-size: 32rpx;
    margin-bottom: 20rpx;
    font-weight: 700;
    color: rgb(48, 49, 51);
    line-height: 46rpx;
  }
  .videos {
    display: flex;
    margin-top: 20rpx;
    .addVideo {
      width: 160rpx;
      height: 160rpx;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      border: 1px dashed rgba(142, 84, 244, 1);
      margin-right: 10rpx;
      border-radius: 16rpx;
      transform: translateY(18rpx);
      margin-bottom: 36rpx;
    }
  }
}
.bottom {
  height: 100rpx;
  width: 100%;
  background-color: #fff;
  position: fixed;
  bottom: 0;
  left: 0;
  .bottom-btn {
    height: 88rpx;
    width: 686rpx;
    background-color: rgba(142, 84, 244, 1);
    border-radius: 8rpx;
    font-size: 32rpx;
    color: #fff;
  }
}
.bottom1 {
    width: 100%;
    background-color: #fff;
    position: fixed;
    bottom: 0;
    left: 0;
    padding-bottom: 68rpx;
    padding-top: 10rpx;
    .bottom-btn {
      height: 88rpx;
      width: 686rpx;
      background-color: rgb(241,241,241);
      color: rgb(192,196,204);
      border-radius: 8rpx;
      font-size: 32rpx;
      line-height: 88rpx;
    }
  }
.top-content {
  background-color: #fff;
  padding: 26rpx 32rpx;
  margin-top: 24rpx;
  .top-ai {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    font-size: 28rpx;
  }
  .top-material {
    width: 638rpx;
    height: 80rpx;
    background-color: rgba(249, 249, 249, 1);
    border-radius: 8rpx;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin: 12rpx;
    padding: 0 12rpx;
    font-size: 28rpx;
  }
}
.del {
  padding: 30rpx;
}
.content{
  width: 100%;
  height: 1000rpx;
  border-radius: 32rpx 32rpx 0 0;
  background-color: #fff;
  .from{
    overflow-y: scroll;
    width: 690rpx;
    height: 1044rpx;
    background-color: rgb(249,249,249);
    border-radius: 16rpx;
    padding: 0 30rpx;
    padding-bottom: 356rpx;
    margin: 30rpx;
    box-sizing: border-box;
    .name{
      display: flex;
      justify-content: space-between;
      align-items: center;
      width: 630rpx;
      height: 116rpx;
      font-size: 30rpx;
      color: rgb(69,70,74);
      border-bottom: 1px solid rgb(220, 223, 230);
      .input{
        text-align: right;
      }
    }

  }
  .close {
    width: 100%;
    height: 108rpx;
    text-align: center;
    line-height: 108rpx;
    font-size: 32rpx;
    font-weight: 700;
    color: rgb(48, 49, 51);
    border-bottom: 1px solid rgb(220, 223, 230);
    .close-btn {
      position: absolute;
      top: 30rpx;
      left: 30rpx;
      width: 48rpx;
      height: 48rpx;
    }
    .addbtn {
      position: absolute;
      right: 30rpx;
      font-size: 28rpx;
      color: rgb(142, 84, 244);
    }
  }
  .scroll{
    height: 64rpx;
    margin: 30rpx 30rpx 30rpx 30rpx;
    font-size: 28rpx;
    color: rgb(144,147,153);
    white-space: nowrap;
    .scroll-item{
      display: inline-block;
      // width: 172rpx;
      height: 64rpx;
      padding: 0 30rpx;
      text-align: center;
      line-height: 64rpx;
      font-size: 28rpx;
      color: rgb(144, 147, 153);
      background-color: #fff;
      margin-right: 30rpx;
      border-radius: 8rpx;
      box-sizing: border-box;
      &:nth-child(1){
        margin-left: 30rpx;
      }
    }
  }
  .kong{
    width: 610rpx;
    margin: 120rpx 70rpx 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-size: 24rpx;
    color: rgb(144, 147, 153);
  }
  .list{
    overflow-y: scroll;
    padding: 0 30rpx;
    height: 598rpx;
    padding-bottom: 170rpx;
    .library-item{
      width: 690rpx;
      padding: 30rpx;
      box-sizing: border-box;
      font-size: 28rpx;
      color: rgb(69,70,74);
      border-radius: 12rpx;
      border: 1px solid transparent;
      margin-bottom: 30rpx;
      background-color: rgb(249,249,249);
    }
    .bottom-btn1 {
      position: fixed;
    bottom: 0;
    left: 0;
    background-color: #fff;
    box-sizing: border-box;
    display: flex;
    justify-content: center;
    width: 100%;
    height: 166rpx;
    padding: 10rpx 30rpx 0;
    .all {
      display: flex;
      align-items: center;
      height: 88rpx;
      font-size: 28rpx;
      color: rgb(144, 147, 153);
    }
    .verify {
      width: 552rpx;
      height: 86rpx;
      padding: 0;
      margin: 0;
      text-align: center;
      line-height: 86rpx;
      color: #fff;
      background-color: rgb(142, 84, 244);
      font-size: 32rpx;
      margin-left: 18rpx;
    }
  }
  }
  .textarea{
    width: 690rpx;
    height: 180rpx;
    padding: 30rpx;
    box-sizing: border-box;
    border-radius: 16rpx;
    margin-left: 30rpx;
    border: 1px solid rgb(220, 223, 230);
  }
  .zi{
    position: absolute;
    bottom: 594rpx;
    right: 60rpx;
    font-size: 24rpx;
    color: rgb(144, 147, 153);
  }
  .flxed{
          width: 100%;
          height: 166rpx;
          position: fixed;
          bottom: 0;
          left: 0;
          background-color: #fff;
          .tianjia{
            width: 690rpx;
            height: 88rpx;
            margin: 10rpx 30rpx 0;
            font-size: 32rpx;
            text-align: center;
            line-height: 88rpx;
            background-color: rgba(241, 241, 241, 1);
            color: rgb(192,196,204);
          }
        }
  .item{
    width: 690rpx;
    margin: 30rpx;
    border-radius: 24rpx;
    border: 1px solid rgb(220,223,230);
    .name{
      width: 630rpx;
      margin: 36rpx 30rpx;
      display: flex;
      justify-content: space-between;
      font-size: 28rpx;
      color: rgb(144,147,153);
      .text{
        color: rgb(69,70,74);
      }
    }
  }
}
.tianjia-style{
  background-color: rgb(142,84,244) !important;
  color: #fff !important;
}
.textarea-style{
  color: rgb(142, 84, 244) !important;
}
.scroll-style{
  background-color: rgb(142,84,244) !important;
  color: #fff !important;
}
.active-item{
  border: 1px solid rgb(142, 84, 244) !important;
}
.active-tem{
  border: 1px solid rgb(142, 84, 244) !important;
}
</style>
